//
//  TKIMDDLog+LOGV.h
//  Lumberjack
//
//  Created by Mike Pontillo on 11/20/12.
//
//

#ifndef TKIM_Lumberjack_DDLog_LOGV_h
#define TKIM_Lumberjack_DDLog_LOGV_h

#import "TKIMDDLog.h"


#define TKIM_LOGV_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, avalist) \
  [TKIMDDLog log:isAsynchronous                                                  \
       level:lvl                                                             \
        flag:flg                                                             \
     context:ctx                                                             \
        file:__FILE__                                                        \
    function:fnct                                                            \
        line:__LINE__                                                        \
         tag:atag                                                            \
      format:frmt                                                            \
        args:avalist]

#define TKIM_LOGV_OBJC_MACRO(async, lvl, flg, ctx, frmt, avalist) \
             TKIM_LOGV_MACRO(async, lvl, flg, ctx, nil, sel_getName(_cmd), frmt, avalist)

#define TKIM_LOGV_C_MACRO(async, lvl, flg, ctx, frmt, avalist) \
          TKIM_LOGV_MACRO(async, lvl, flg, ctx, nil, __FUNCTION__, frmt, avalist)



#define  TKIM_SYNC_LOGV_OBJC_MACRO(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_OBJC_MACRO( NO, lvl, flg, ctx, frmt, avalist)

#define TKIM_ASYNC_LOGV_OBJC_MACRO(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_OBJC_MACRO(YES, lvl, flg, ctx, frmt, avalist)

#define  TKIM_SYNC_LOGV_C_MACRO(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_C_MACRO( NO, lvl, flg, ctx, frmt, avalist)

#define TKIM_ASYNC_LOGV_C_MACRO(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_C_MACRO(YES, lvl, flg, ctx, frmt, avalist)



#define TKIM_LOGV_MAYBE(async, lvl, flg, ctx, fnct, frmt, avalist) \
  do { if(lvl & flg) TKIM_LOGV_MACRO(async, lvl, flg, ctx, nil, fnct, frmt, avalist); } while(0)

#define TKIM_LOGV_OBJC_MAYBE(async, lvl, flg, ctx, frmt, avalist) \
             TKIM_LOGV_MAYBE(async, lvl, flg, ctx, sel_getName(_cmd), frmt, avalist)

#define TKIM_LOGV_C_MAYBE(async, lvl, flg, ctx, frmt, avalist) \
          TKIM_LOGV_MAYBE(async, lvl, flg, ctx, __FUNCTION__, frmt, avalist)

#define  TKIM_SYNC_LOGV_OBJC_MAYBE(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_OBJC_MAYBE( NO, lvl, flg, ctx, frmt, avalist)

#define TKIM_ASYNC_LOGV_OBJC_MAYBE(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_OBJC_MAYBE(YES, lvl, flg, ctx, frmt, avalist)

#define  TKIM_SYNC_LOGV_C_MAYBE(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_C_MAYBE( NO, lvl, flg, ctx, frmt, avalist)

#define TKIM_ASYNC_LOGV_C_MAYBE(lvl, flg, ctx, frmt, avalist) \
              TKIM_LOGV_C_MAYBE(YES, lvl, flg, ctx, frmt, avalist)



#define TKIM_LOGV_OBJC_TAG_MACRO(async, lvl, flg, ctx, tag, frmt, avalist) \
                 TKIM_LOGV_MACRO(async, lvl, flg, ctx, tag, sel_getName(_cmd), frmt, avalist)

#define TKIM_LOGV_C_TAG_MACRO(async, lvl, flg, ctx, tag, frmt, avalist) \
              TKIM_LOGV_MACRO(async, lvl, flg, ctx, tag, __FUNCTION__, frmt, avalist)

#define TKIM_LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, avalist) \
  do { if(lvl & flg) TKIM_LOGV_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, avalist); } while(0)

#define TKIM_LOGV_OBJC_TAG_MAYBE(async, lvl, flg, ctx, tag, frmt, avalist) \
             TKIM_LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, sel_getName(_cmd), frmt, avalist)

#define TKIM_LOGV_C_TAG_MAYBE(async, lvl, flg, ctx, tag, frmt, avalist) \
          TKIM_LOGV_TAG_MAYBE(async, lvl, flg, ctx, tag, __FUNCTION__, frmt, avalist)



#define TKIMDDLogvError(frmt, avalist)   TKIM_LOGV_OBJC_MAYBE(TKIM_LOG_ASYNC_ERROR,   ddLogLevel, TKIM_LOG_FLAG_ERROR,   0, frmt, avalist)
#define TKIMDDLogvWarn(frmt, avalist)    TKIM_LOGV_OBJC_MAYBE(TKIM_LOG_ASYNC_WARN,    ddLogLevel, TKIM_LOG_FLAG_WARN,    0, frmt, avalist)
#define TKIMDDLogvInfo(frmt, avalist)    TKIM_LOGV_OBJC_MAYBE(TKIM_LOG_ASYNC_INFO,    ddLogLevel, TKIM_LOG_FLAG_INFO,    0, frmt, avalist)
#define TKIMDDLogvVerbose(frmt, avalist) TKIM_LOGV_OBJC_MAYBE(TKIM_LOG_ASYNC_VERBOSE, ddLogLevel, TKIM_LOG_FLAG_VERBOSE, 0, frmt, avalist)

#define TKIMDDLogvCError(frmt, avalist)   TKIM_LOGV_C_MAYBE(TKIM_LOG_ASYNC_ERROR,   ddLogLevel, TKIM_LOG_FLAG_ERROR,   0, frmt, avalist)
#define TKIMDDLogvCWarn(frmt, avalist)    TKIM_LOGV_C_MAYBE(TKIM_LOG_ASYNC_WARN,    ddLogLevel, TKIM_LOG_FLAG_WARN,    0, frmt, avalist)
#define TKIMDDLogvCInfo(frmt, avalist)    TKIM_LOGV_C_MAYBE(TKIM_LOG_ASYNC_INFO,    ddLogLevel, TKIM_LOG_FLAG_INFO,    0, frmt, avalist)
#define TKIMDDLogvCVerbose(frmt, avalist) TKIM_LOGV_C_MAYBE(TKIM_LOG_ASYNC_VERBOSE, ddLogLevel, TKIM_LOG_FLAG_VERBOSE, 0, frmt, avalist)

#endif
